using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
    /// <summary>
    /// Controller class for Advertiser2
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class Advertiser2Controller
    {
        // Preload our schema..
        Advertiser2 thisSchemaLoad = new Advertiser2();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public Advertiser2Collection FetchAll()
        {
            Advertiser2Collection coll = new Advertiser2Collection();
            Query qry = new Query(Advertiser2.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public Advertiser2Collection FetchByID(object AdvertiserID)
        {
            Advertiser2Collection coll = new Advertiser2Collection().Where("AdvertiserID", AdvertiserID).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public Advertiser2Collection FetchByQuery(Query qry)
        {
            Advertiser2Collection coll = new Advertiser2Collection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object AdvertiserID)
        {
            return (Advertiser2.Delete(AdvertiserID) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object AdvertiserID)
        {
            return (Advertiser2.Destroy(AdvertiserID) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int AdvertiserCode,string AdvertiserName,int? MediaCode,string MediaType,bool? Tv,bool? Rd,bool? Cb,bool? Pr,bool? Od,bool? Ns,DateTime? DateAdded,DateTime? DateModified,bool? InX)
	    {
		    Advertiser2 item = new Advertiser2();
		    
            item.AdvertiserCode = AdvertiserCode;
            
            item.AdvertiserName = AdvertiserName;
            
            item.MediaCode = MediaCode;
            
            item.MediaType = MediaType;
            
            item.Tv = Tv;
            
            item.Rd = Rd;
            
            item.Cb = Cb;
            
            item.Pr = Pr;
            
            item.Od = Od;
            
            item.Ns = Ns;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
            item.InX = InX;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int AdvertiserID,int AdvertiserCode,string AdvertiserName,int? MediaCode,string MediaType,bool? Tv,bool? Rd,bool? Cb,bool? Pr,bool? Od,bool? Ns,DateTime? DateAdded,DateTime? DateModified,bool? InX)
	    {
		    Advertiser2 item = new Advertiser2();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.AdvertiserID = AdvertiserID;
				
			item.AdvertiserCode = AdvertiserCode;
				
			item.AdvertiserName = AdvertiserName;
				
			item.MediaCode = MediaCode;
				
			item.MediaType = MediaType;
				
			item.Tv = Tv;
				
			item.Rd = Rd;
				
			item.Cb = Cb;
				
			item.Pr = Pr;
				
			item.Od = Od;
				
			item.Ns = Ns;
				
			item.DateAdded = DateAdded;
				
			item.DateModified = DateModified;
				
			item.InX = InX;
				
	        item.Save(UserName);
	    }
    }
}
